package com.lesso.yzh.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.yzh.sunflower.domain.repository.AttendanceRuleRepository;
import com.lesso.yzh.sunflower.infra.assembler.AttendanceRuleAssembler;
import com.lesso.yzh.sunflower.model.AttendanceRule;
import com.lesso.yzh.sunflower.pojo.dto.AttendanceRuleDTO;
import com.lesso.yzh.sunflower.pojo.dto.AttendanceRuleQueryDTO;
import com.lesso.yzh.sunflower.pojo.dto.AttendanceRuleUpdateDTO;
import com.lesso.yzh.sunflower.pojo.vo.AttendanceRuleVO;
import org.springframework.stereotype.Service;

@Service
public class AttendanceRuleDomainService {
    private final AttendanceRuleRepository attendanceRuleRepository;

    public AttendanceRuleDomainService(AttendanceRuleRepository attendanceRuleRepository){
        this.attendanceRuleRepository=attendanceRuleRepository;
    }

    public Integer save(AttendanceRuleDTO dto){
        AttendanceRule attendanceRule= AttendanceRuleAssembler.INSTANCE.dtoEntity(dto);
        return attendanceRuleRepository.save(attendanceRule);
    }

    public Integer update(AttendanceRuleUpdateDTO dto) {
        AttendanceRule attendanceRule=AttendanceRuleAssembler.INSTANCE.dtoUpdateEntity(dto);
        return attendanceRuleRepository.update(attendanceRule);
    }

    public void deleteById(Long id) {
        attendanceRuleRepository.removeById(id);
    }

    public Page<AttendanceRuleVO> page(AttendanceRuleQueryDTO dto) {
        return attendanceRuleRepository.getPageList(dto);
    }

    public Page<AttendanceRuleVO> customPage(AttendanceRuleQueryDTO dto) {
        return attendanceRuleRepository.getCustomPageList(dto);
    }
}
